package com.jeomo.mem.provider.web;

import com.jeomo.common.core.dto.PageQueryDto;
import com.jeomo.common.core.dto.PageResponseDto;
import com.jeomo.common.core.request.PageRequest;
import com.jeomo.common.core.result.CommonResult;
import com.jeomo.common.core.util.BeanCopyUtil;
import com.jeomo.common.core.vo.PageResponseVo;
import com.jeomo.mem.provider.request.MemberPointsAdjustReq;
import com.jeomo.mem.provider.vo.MemberPointsAdjustVo;
import com.jeomo.mem.starter.entity.MemberPointsAdjust;
import com.jeomo.mem.starter.service.IMemPointsAdjustService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 会员积分调整
 *
 * @author:Jackpot
 * @create 2020-12-23 16:24
 * @description:
 */
@RestController
@RequestMapping("/member/points")
public class MemberPointsAdjustController {

    @Autowired
    private IMemPointsAdjustService memPointsAdjustService;


    @ApiOperation("会员积分调整接口")
    @PostMapping("/adjust")
    public CommonResult pointsAdjust(@RequestBody @Validated MemberPointsAdjustReq memberPointsAdjustReq){

        MemberPointsAdjust memberPointsAdjust = BeanCopyUtil.copyProperties(memberPointsAdjustReq, MemberPointsAdjust.class);
        boolean result = memPointsAdjustService.insertPointsAdjust(memberPointsAdjust);
        return result?CommonResult.success("操作成功!"):CommonResult.failure("操作失败!");
    }

    @ApiOperation("分页查询会员积分调整列表")
    @PostMapping("/adjust/pages")
    public CommonResult getPages(@RequestBody PageRequest pageRequest){

        PageQueryDto pageQueryDto = BeanCopyUtil.copyProperties(pageRequest, PageQueryDto.class);
        PageResponseDto pageResponseDto = memPointsAdjustService.pageSearch(pageQueryDto);
        PageResponseVo<MemberPointsAdjustVo> memberPointsAdjustVo = BeanCopyUtil.copyPageProperties(pageResponseDto, MemberPointsAdjustVo.class);
        return CommonResult.success(memberPointsAdjustVo);
    }
    @ApiOperation("查询单条会员积分调整详情")
    @GetMapping("/adjust/one/{code}")
    public CommonResult getOne(@PathVariable String code){

        MemberPointsAdjust oneDetail = memPointsAdjustService.getOneDetail(code);
        return CommonResult.success(oneDetail);
    }


}
